import fetch from 'utils/fetch';

export function loginByEmail(username, password, verification) {
  const data = {
    username,
    password,
    verification
  };
  return fetch({
    url: '/api/auth/jwt/token',
    method: 'post',
    headers: {
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type',
      'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS',
    },
    data
  });
}

export function logout(token) {
  return fetch({
    url: '/api/auth/jwt/invalid',
    method: 'get',
    params: { token }
  });
}
//获取用户分配的菜单权限
export function getAuthorityPlatform(token) {
  return fetch({
    url: '/api/admin/flPlatform/getAuthorityPlatform',
    method: 'post',
    params: { token }
  });
}
export function getInfo(token) {
  return fetch({
    url: '/api/admin/user/front/info',
    method: 'get',
    params: { token }
  });
}

export function getMenus(token, newSysCompanyCode) {
  return fetch({
    url: '/api/admin/user/front/menus',
    method: 'get',
    params: {
      'token': token,
      'sysCompanyCode': newSysCompanyCode,
      'platform': 4
    }
  });
}

export function getAllMenus() {
  return fetch({
    url: '/api/admin/user/front/menu/all',
    method: 'get'
  });
}

//查询用户对应的网格参数
export function findByUserId(userId) {
  return fetch({
    url: `/api/admin/flUserButton/gridfind?user_id=${userId}`,
    method: 'get'
  })
}
//admin/flUserButton/update?user_id=…&button_id=…
//put
export function ugridPdate(obj) {
  return fetch({
    url: `/api/admin/flUserButton/update`,
    method: 'put',
    data: obj
  })
}
//admin/flSwitchforla/{id}
//put
export function flSwitchforla(id, obj) {
  return fetch({
    url: `/api/admin/flSwitchforla/${id}`,
    method: 'put',
    data: obj
  })
}
//http://localhost:8765/api/admin/flLittlebutton
//get
export function flLittlebutton() {
  return fetch({
    url: `/api/admin/flLittlebutton`,
    method: 'get',
  })
}
// 1.添加小图标数据
// admin/ flLittlebutton
// post
export function postFlLittlebutton(obj) {
  return fetch({
    url: `/api/admin/flLittlebutton`,
    method: 'post',
    data: obj
  })
}

export function flGroupBtttonAddAll(userId, obj) {
  return fetch({
    url: `/api/admin/flGroupBttton/addAll/${userId}`,
    method: 'post',
    data: obj
  })
}

// 14.根据角色id查询用户小图标
// admin/flGroupBttton/ findBygroupId? group_id=…
// get
export function getSFlLittlebutton(groupId) {
  return fetch({
    url: `/api/admin/flGroupBttton/findBygroupId?group_id=${groupId}`,
    method: 'get',
  })
}